package org.janon.httpproxy.server.method;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

import org.janon.httpproxy.ClientReadFromServer;
import org.janon.httpproxy.HttpModel;
import org.janon.httpproxy.HttpSession;
import org.janon.httpproxy.HttpUtil;
import org.janon.httpproxy.RequestLogStream;

public class LocalGetMethod
{
	public static ClientReadFromServer doMethod(HttpModel httpModel, BufferedInputStream server_in, BufferedOutputStream server_out, BufferedInputStream client_in, BufferedOutputStream client_out, HttpSession session, RequestLogStream rls) throws Exception
	{
		InputStream is = new FileInputStream(new File("server.log.txt"));
		client_out.write((httpModel.getHttpType() + " 200 OK" + HttpUtil.CRLF).getBytes());
		HttpUtil.sendInitHeader(client_out);
		client_out.write(("Content-Length: " + is.available() + HttpUtil.CRLF).getBytes());
		client_out.write(HttpUtil.CRLF.getBytes());
		byte[] b = new byte[96000];
		int l = 0;
		while((l=is.read(b))!=-1)
		{
			client_out.write(b, 0, l);
			client_out.flush();
		}
		is.close();
		client_out.flush();
		return null;
	}
}
